|
1
|
|
|
import fse from 'fs-extra' |
|
2
|
|
|
import {saveHtml} from './cms/operations/save' |
|
3
|
|
|
import path from 'path' |
|
4
|
|
|
|
|
5
|
|
|
import { |
|
6
|
|
|
Util, |
|
|
|
|
|
|
7
|
|
|
cmsData, |
|
8
|
|
|
FileParser, |
|
9
|
|
|
config, |
|
10
|
|
|
fileUtils, |
|
11
|
|
|
fileAttr, |
|
12
|
|
|
cmsTemplate, |
|
13
|
|
|
Page |
|
14
|
|
|
} from './' |
|
15
|
|
|
|
|
16
|
|
|
class Builder { |
|
17
|
|
|
|
|
18
|
|
|
constructor(root, folder, dest, flow){ |
|
19
|
|
|
this.pathToJson = path.join(root, config.data.url) |
|
20
|
|
|
var files = fileAttr.filterLatestVersion(FileParser.getFiles(this.pathToJson, config.data.url), flow) |
|
21
|
|
|
|
|
22
|
|
|
if(flow === 'publish') { |
|
23
|
|
|
files = FileParser.getFiles(path.join(root, config.publish.url), new RegExp('.' + config.files.templates.extension)) |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
var build = function (index) { |
|
27
|
|
|
var file = files[index] |
|
28
|
|
|
if(file.path.indexOf('.' + config.files.templates.extension) > -1){ |
|
29
|
|
|
file.path = file.path.replace(config.publish.url, config.data.url) |
|
30
|
|
|
.replace('.' + config.files.templates.extension, '.json') |
|
31
|
|
|
|
|
32
|
|
|
var json = fse.readJsonSync(file.path) |
|
33
|
|
|
var text = cmsTemplate.template.getTemplate(json.abe_meta.template) |
|
34
|
|
|
|
|
35
|
|
|
cmsData.source.getDataList(fileUtils.removeLast(json.abe_meta.link), text, json) |
|
36
|
|
|
.then(() => { |
|
37
|
|
|
var page = new Page(json.abe_meta.template, text, json, true) |
|
38
|
|
|
saveHtml(path.join(root, dest + json.abe_meta.link), page.html) |
|
39
|
|
|
if(files[index + 1]) build(index + 1) |
|
|
|
|
|
|
40
|
|
|
}).catch(function(e) { |
|
41
|
|
|
console.error(e) |
|
42
|
|
|
if(files[index + 1]) build(index + 1) |
|
|
|
|
|
|
43
|
|
|
}) |
|
44
|
|
|
} |
|
45
|
|
|
else if(file.path.indexOf('.json') > -1){ |
|
46
|
|
|
var json = fse.readJsonSync(file.path) |
|
|
|
|
|
|
47
|
|
|
var text = cmsTemplate.template.getTemplate(json.abe_meta.template) |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
cmsData.source.getDataList(fileUtils.removeLast(json.abe_meta.link), text, json) |
|
50
|
|
|
.then(() => { |
|
51
|
|
|
var page = new Page(json.abe_meta.template, text, json, true) |
|
52
|
|
|
saveHtml(path.join(root, dest + json.abe_meta.link), page.html) |
|
53
|
|
|
if(files[index + 1]) build(index + 1) |
|
|
|
|
|
|
54
|
|
|
}).catch(function(e) { |
|
55
|
|
|
console.error(e) |
|
56
|
|
|
if(files[index + 1]) build(index + 1) |
|
|
|
|
|
|
57
|
|
|
}) |
|
58
|
|
|
} |
|
59
|
|
|
else if(files[index + 1]) build(index + 1) |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
build(0) |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if(process.env.ROOT && process.env.FOLDER && process.env.DEST){ |
|
69
|
|
|
config.set({root: process.env.ROOT}) |
|
70
|
|
|
var dest = process.env.DEST || 'tmp' |
|
71
|
|
|
var flow = process.env.FLOW || 'draft' |
|
72
|
|
|
new Builder(process.env.ROOT, process.env.FOLDER, dest, flow) |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|